#include "GraveFactory.h"

#include "ccMacros.h"
#include "MapGrid.h"

GraveFactory* GraveFactory::m_GraveFactory = NULL;

const float GraveFactory::CREATE_INTERVAL = 1.0f;

GraveFactory* GraveFactory::Create( CCPoint startPoint,CCPoint endPoint )
{
	if(m_GraveFactory == NULL){
		m_GraveFactory = new GraveFactory(startPoint,endPoint);
		m_GraveFactory->autorelease();
		m_GraveFactory->retain();
	}

	return m_GraveFactory;
}

void GraveFactory::Destory()
{
	if(m_GraveFactory != NULL){
		m_GraveFactory->release();
	}
}

Zombie* GraveFactory::CreateZombie()
{
	int rndR = (int)(CCRANDOM_0_1()*(MapGrid::SLOT_ROW_COUNT +1));
	CCPoint startPoint = ccp(m_startPoint.x,MapGrid::GetColumnCoordinate(rndR));

	int rndC = (int)(CCRANDOM_0_1()*(MapGrid::SLOT_ROW_COUNT +1));
	CCPoint endPoint = ccp(m_startPoint.x,MapGrid::GetLeftOutRange().y);

	if(this->m_currentCreatedNum++ < GraveFactory::ZOMBIE_COUNT_PER_RUSH){
		Zombie* zombie = Zombie::create(m_currentCreatedNum,startPoint,endPoint);
		return zombie;
	}

	return NULL;
}
